//package org.activoricordi.app.snippet
package edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.snippet

/**
 * Created with IntelliJ IDEA.
 * User: naru
 * Date: 3/30/13
 * Time: 12:24 PM
 * To change this template use File | Settings | File Templates.
 */

import net.liftweb.common.{Box,Full,Empty,Failure,ParamFailure}
import net.liftweb._
import  edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.model._
import util._
import util.Helpers._
import http._
import xml.{Text, NodeSeq}

class ViewCompound {
  /**
   * get the id of compound
   */


  var id = S.param("id") openOr ""
  /**
   * search the Compound by id
   */
  var compound = try {
    Compound.findByKey(id.toLong)
  } catch {
    case e:NumberFormatException => Empty
  }

  def view(html : NodeSeq): NodeSeq = {
    /**
     * Map the Compound attribute on view page
     */
    compound map ({ i =>
      bind("compound", html,

        "compoundName" -> i.compoundName,
        "inchiKey" -> i.inchiKey,
        "massSpectra" ->i.massSpectra,
        "comments" -> i.retentionTime
      )

      /**
       * error Message if no Compound found for regarding id
       */
    }) openOr Text("Invalid Item")

  }
}
